package org.example.demo1.controller; // 包路径已更正

import org.example.demo1.dto.NamespaceJaegerMetricsDto; // 导入路径已更正
import org.example.demo1.service.JaegerMonitorService; // 导入路径已更正
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Jaeger 监控 REST API 控制器
 */
@RestController
@RequestMapping("/api/monitor/jaeger")
@Slf4j
public class JaegerMonitorController {

    private final JaegerMonitorService jaegerMonitorService;

    public JaegerMonitorController(JaegerMonitorService jaegerMonitorService) {
        this.jaegerMonitorService = jaegerMonitorService;
    }

    /**
     * 获取 Jaeger 追踪概览指标，按命名空间分组
     * 前端会调用此接口来填充 Jaeger 监控卡片
     * GET /api/monitor/jaeger/metrics
     * @return 包含每个命名空间 Jaeger 指标的列表
     */
    @GetMapping("/metrics")
    public ResponseEntity<List<NamespaceJaegerMetricsDto>> getJaegerMetrics() {
        log.info("收到获取 Jaeger 指标的请求（按命名空间分组）。");
        List<NamespaceJaegerMetricsDto> metrics = jaegerMonitorService.getJaegerMetricsGroupedByNamespace();
        return ResponseEntity.ok(metrics);
    }
}